<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<!-- <script src='/Public/jquery.min.js'></script> -->
  <script src="https://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
  
	<script src='/Public/foundation/js/foundation.min.js'></script>
	<link rel="stylesheet" href="/Public/foundation/css/foundation.min.css">
  <script src='/Public/jquery.cityselect.js'></script>
  <script src='/Public/jquery.datetimepicker.full.js'></script>
  <link rel="stylesheet" href="/Public/jquery.datetimepicker.css">
   <script src="http://cdn.static.runoob.com/libs/foundation/5.5.3/js/vendor/modernizr.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<nav class="top-bar" data-topbar>
  <ul class="title-area">
    <li class="name">
      <h1><a href="#">后台管理</a></h1>
    </li>
  </ul>

  <section class="top-bar-section">
    <ul class="right">
      <li><a href=""><?php echo (session('name')); ?></a></li>
      <li><a href="<?php echo U('Login/doLogout');?>">退出</a></li>
    </ul>
  </section>
</nav>

<div class="small-2 columns">
<ul class="side-nav">
 <?php if(is_array($nav)): $i = 0; $__LIST__ = $nav;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><li><a href="<?php echo U($vo['url']);?>" target='<?php echo ($vo["target"]?"_blank":null); ?>'><?php echo ($vo["mname"]); ?></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
    </ul>
</div>
<div class="small-10 columns">

<!-- <form action="?" method='get'> -->
    <!-- <fieldset>
        
            <?php if(is_array($vvvo)): $i = 0; $__LIST__ = $vvvo;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$list): $mod = ($i % 2 );++$i;?><input type="checkbox" name='role_name' value="<?php echo ($list["role_name"]); ?>"><?php echo ($list["role_name"]); endforeach; endif; else: echo "" ;endif; ?>
            <input type="submit" value='搜索'>
       
    </fieldset> -->
<!-- </form>
 --><table id='Tbl'>
<thead>
	<tr>
		<th><input type="checkbox" onclick="selectAll(this)" value='全选'></th>
		<th>编号</th>
		<th>角色名</th>
		<!-- <th>菜单编号</th> -->
		<th>操作</th>
	</tr>
	</thead>
	<tbody>
	<?php if(is_array($roles)): $i = 0; $__LIST__ = $roles;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr id="row_<?php echo ($vo["role_id"]); ?>">
			<td><input type="checkbox" class='select' value='<?php echo ($vo["role_id"]); ?>' ></td>
			<td><?php echo ($vo["role_id"]); ?></td>
			 <td><input name="role_name" class="clss"  type="text" value="<?php echo ($vo["role_name"]); ?>"></td> 
             
			<!-- <td><input name="menu_ids" class="clss"  type="text" value="<?php echo ($vo["menu_ids"]); ?>"></td>    -->
			<!--<td>
			
             <!-- <div class="switch tiny">
              <input onclick="lock(this)" value="<?php echo ($vo["role_id"]); ?>" id="lock_<?php echo ($vo["role_id"]); ?>" type="checkbox"  <?php echo ($vo['lock']?'checked':''); ?>>
                <label for="lock_<?php echo ($vo["role_id"]); ?>"></label>
                </div>  -->  
			<!-- </td>   -->
			<td>
			<a href="<?php echo U('editRoles',['role_id'=>$vo['role_id']]);?>">角色权限编辑</a>
			<!-- <button style='display:none' onclick='save("<?php echo ($vo["role_id"]); ?>")' type="button" class="save">保存</button> -->
			</td>
		</tr><?php endforeach; endif; else: echo "" ;endif; ?>
	</tbody>
</table>
<input type="button" class="button" onclick="moreDel()" value='删除(批量)'>
<input type="button" class="button" onclick="unSelect()" value='反选'>
<input type="button" class="button" onclick="add()" value='添加'>
<script>
        function selectAll(obj) {
            $('#Tbl tbody .select').prop('checked',$(obj).prop('checked'));
        }
        function unSelect() {
            $('#Tbl tbody .select').map(function(){
                $(this).prop('checked',!$(this).prop('checked'));
            });
        }
        function moreDel() {
            if(!confirm('确定删除吗?')){
                return;
            }
            var ids = $('#Tbl tbody .select:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            $.post('<?php echo U("doDelRole");?>',{ids:ids},function (data) {
                if(data.error ==0)alert(data.msg);
            });
        }
        
        function add(){
            $.get("<?php echo U('lastId');?>", '',
            function(id){
               var id= parseInt(id)+1;

                var html ="     <tr>"+
    "           <td><input  type=\'checkbox\' class=\'select\' value=\'\' ></td>"+
    "           <td>"+id+"</td>"+
    "           <td><input id=\'row_"+id+"\' name=\'role_name\' class=\'clss\'  type=\'text\' value=\'\'></td>"+
    
    
    
    "           <td>"+
    "           <a  onclick='jump("+id+")'>角色权限编辑</a>"+
    
    "           </td>"+
    "       </tr>";

            $('tbody').append(html);
            
            });
        }
		function jump(id){
			role_name=$('#row_'+id).val();
			window.location.href='<?php echo U('jump');?>?role_name='+role_name;
		}

        


</script>

</div>

</body>
</html>